package com.wlyuan.index.domain.source.valueobj;

import com.wlyuan.core.marker.INamed;
import com.wlyuan.core.marker.NamedMap;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.var;

import java.util.Map;
import java.util.Optional;

@RequiredArgsConstructor
@Getter
public enum CombineStatus implements INamed<Integer> {
    WAIT_DISPATCH(10, "待调度", false),
    DISPATCHED(20, "已调度", false),
    WAIT_ACCEPT(21, "待接收", false),
    WAIT_SIGN(30, "待签收", true),
    CLOSED(40, "已关闭", false);


    private final Integer value;
    private final String name;
    private final boolean canQuote;

    private static final Map<Integer, CombineStatus> STATUSES = new NamedMap<>(CombineStatus.values());


    public static CombineStatus valueOf(Integer value, Character character) {
        var status = valueOf(value);
        if (DISPATCHED == status && Character.CARRIER == character) {
            return WAIT_ACCEPT;
        }
        return status;
    }

    public static CombineStatus valueOf(Integer value) {
        return STATUSES.get(value);
    }

    public static boolean canQuote(Integer value) {
        return Optional.ofNullable(value)
                .map(CombineStatus::valueOf)
                .filter(CombineStatus::isCanQuote)
                .isPresent();
    }
}
